package com.woniuxy.store.core.mapper;

import com.woniuxy.store.core.model.PlAddress;
import com.woniuxy.store.core.model.PlOrderitem;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.store.core.vo.OrderItemVo;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author gmx
 * @since 2021-07-05
 */
public interface PlOrderitemMapper extends BaseMapper<PlOrderitem> {
    @Select("SELECT * FROM pl_orderitem oi LEFT JOIN pl_order o ON oi.order_id=o.id WHERE store_id=#{storeId}")
     List<OrderItemVo> selectAll(Integer storeId);

    @Select("select * from pl_orderitem where store_id=#{storeId} and ordertype=1")
    List<OrderItemVo> selectOrderItemByStoreId(Integer storeId);

    @Select("select * from pl_orderitem where store_id=#{storeId} and first_id=#{firstId}")
    List<OrderItemVo> selectByStoreIdFirstId(Integer storeId, Integer firstId);
    @Select("SELECT * FROM pl_orderitem oi LEFT JOIN pl_order o ON oi.order_id=o.id WHERE oi.store_id=#{storeId} AND `status`=0")
    List<OrderItemVo> selectUnpaid(Integer storeId);
    @Select("SELECT * FROM pl_orderitem oi LEFT JOIN pl_order o ON oi.order_id=o.id WHERE oi.store_id=#{storeId} AND `status`=1")
    List<OrderItemVo> selectUnChecked(Integer storeId);
    @Select("SELECT * FROM pl_orderitem oi LEFT JOIN pl_order o ON oi.order_id=o.id WHERE oi.store_id=#{storeId} AND `status`=2")
    List<OrderItemVo> selectUnServiced(Integer storeId);
    @Select("SELECT * FROM pl_orderitem oi LEFT JOIN pl_order o ON oi.order_id=o.id WHERE oi.store_id=#{storeId} AND `status`=3")
    List<OrderItemVo> selectUnEvaluate(Integer storeId);
    @Select("SELECT * FROM pl_orderitem oi LEFT JOIN pl_order o ON oi.order_id=o.id WHERE oi.store_id=#{storeId} AND `status`=4")
    List<OrderItemVo> selectUnAfterSale(Integer storeId);
    @Select("SELECT * FROM pl_orderitem oi LEFT JOIN pl_order o ON oi.order_id=o.id WHERE oi.store_id=#{storeId} AND `status`=5")
    List<OrderItemVo> selectFinished(Integer storeId);
    @Select("SELECT * FROM pl_orderitem oi LEFT JOIN pl_order o ON oi.order_id=o.id WHERE DATEDIFF(createtime,NOW()) =0 and store_id=#{storeId}")
    List<OrderItemVo> selectDay(Integer storeId);
    @Select("SELECT * FROM pl_orderitem oi LEFT JOIN pl_order o ON oi.order_id=o.id  WHERE YEARWEEK(date_format(createtime,'%Y-%m-%d')) = YEARWEEK(now()) and store_id=#{storeId}")
    List<OrderItemVo> selectWeek(Integer storeId);
    @Select("SELECT * FROM pl_orderitem oi LEFT JOIN pl_order o ON oi.order_id=o.id  WHERE date_format(createtime,'%Y-%m')=date_format(now(),'%Y-%m') and store_id=#{storeId}")
    List<OrderItemVo> selectMonth(Integer storeId);
    @Select("select * from pl_orderitem oi LEFT JOIN pl_order o ON oi.order_id=o.id  where QUARTER(createtime)=QUARTER(now()) and store_id=#{storeId}")
    List<OrderItemVo> selectSeason(Integer storeId);
    @Select("SELECT pa.* FROM pl_address pa,pl_orderitem poi,pl_order po,pl_user pu WHERE poi.order_id=po.id AND po.user_id=pu.id AND\n" +
            "pa.user_id=pu.id AND poi.id=#{orderitemId}")
    List<PlAddress> selectAddress(Integer orderitemId);
}
